const app = getApp()
var api = require("../../../utils/mr_xu/api_url.js").api
var common = require('../../../utils/mr_xu/common.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  takePhoto() {
    let that = this
    const ctx = wx.createCameraContext()
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        let path = res.tempImagePath
        that.getCarNo(path)
      }
    })
  },
  chooseImage() {
    let that = this
    wx.chooseImage({
      count:1,
      sourceType:'album',
      success: function(res) {
        let path = res.tempFilePaths[0]
        that.getCarNo(path)
      },
    })
  },
  manualInput() {
    wx.navigateTo({
      url: './order_list?writeCarNo=1&carNo=',
    })
  },
  getCarNo(path) {
    wx.showLoading({
      title: '加载中',
    })
    app.http.post(api.ocr_plate, { data: common.getBase64Data(path)}).then(res => {
      console.log(res)
      if (res.obj) {
        wx.navigateTo({
          url: './order_list?writeCarNo=1&carNo=' + res.obj,
        })
      }
      wx.hideLoading()
    })
  }
})